<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <script type="text/javascript" src="__STATIC__/x-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="__STATIC__/x-admin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/x-admin/css/xadmin.css">
</head>
<body>
<div style="height: 20px"></div>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="#">资源管理</a>
        <a href="#">中考体育</a>
        <a href="#">内容管理</a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<form class="layui-form" action="" id="contents" onsubmit="return false" style="width: 500px">
    <input type="hidden" value="{$contentsInfo.id}" name="id">
    <div class="layui-form-item">
        <label class="layui-form-label">项目名称</label>
        <div class="layui-input-block">
            <select name="project_id"  id="project">
                {foreach $project as $value}
                    <option value="{$value.id}" {if $value.id == $contentsInfo.project_id} selected  {/if}>{$value.title}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">市区名称</label>
        <div class="layui-input-inline">
            <input type="text" name="city" id="city" value="{$city}" placeholder="请输入市区名称" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">比如：北京</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">分数区间</label>
        <div class="layui-input-block">
            <div style="float: left">
                <input type="number" value="{$contentsInfo.high_score}" name="high_score" id="high_score" placeholder="最高分" class="layui-input">
            </div>
            —
            <div style="float: right">
                <input type="number" value="{$contentsInfo.low_score}" name="low_score" id="low_score" placeholder="最低分"  class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">获得分数</label>
        <div class="layui-input-inline">
            <input type="number" value="{$contentsInfo.score}" name="score" id="score" placeholder="获得分数" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="1" title="男" {if $contentsInfo.sex == 1} checked {/if}>
            <input type="radio" name="sex" value="0" title="女" {if $contentsInfo.sex == 0} checked {/if}>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" id="update">立即更新</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script>
    layui.use('form', function(){
        var form = layui.form;
        form.verify({
            high_score: function(value){
                console.log();
            }
            ,low_score: function(value){
                console.log();
            },
            score:function(value){
                console.log();
            }
        });
    });
</script>
<script>
    $("#update").click(function(){
        if(!$('#project option:selected').val()){
            layer.msg('请选择需要添加的项目',{icon:5,time:2000});
            return;
        }
        if(!$("#city").val()){
            layer.msg('请输入城市名称',{icon:5,time:2000});
            return;
        }
        if(!$("#high_score").val()){
            layer.msg('请输入最高分',{icon:5,time:2000});
            return;
        }
        if(!$("#low_score").val()){
            layer.msg('请输入最低分',{icon:5,time:2000});
            return;
        }
        if(!$("#score").val()){
            layer.msg('请输入获得的分数',{icon:5,time:2000});
            return;
        }
        if(!$("input[name=sex]:checked").val()){
            layer.msg('请选择性别',{icon:5,time:2000});
            return;
        }
        $.ajax({
            url:"{:url('/contents/update')}",
            type:"post",
            data:$("#contents").serialize(),
            dataType:"json",
            success:function(res){
                if(res.code){
                    layer.msg(res.msg,{icon:1,time:2000},function(){
                        window.location.reload();
                    });
                    return;
                }else{
                    layer.msg(res.msg,{icon:5,time:2000});
                }
            }
        });
    });
</script>
</body>
</html>